
import TableList from "@components/templates/customtablelist";
import { HttpLabelDifferenceList, HttpCarrierAllList } from '@/service/api/views'
import { mapState,mapGetters } from "vuex";
import compUpdate from './update';
import compsoUpload from "@components/templates/selectupload";
export default {
    mixins: [TableList],
    components: {
        compUpdate,
        compsoUpload,
    },
    data() {
        return {
            // totals: 0,
            isMixin: true,
            Tools: {show: true},
            Tabs: {show: true},
            formData:{
                search:{
                }
            },
            Searchs: {
                show: true,
                labelWidth: 120,
            },
            Plugins: {show: true},
            carrierList: [],
            errStatus: [
                {value:0, label:'无异常', color: '#70B603'},
                {value:1, label:'金额差异', color: '#A30014'},
                {value:2, label:'二次入账', color: '#D9001B'},
                {value:3, label:'匹配失败', color: '#F59A23'},
            ],
        }
    },
    created(){
        HttpCarrierAllList().then(res=>{
            this.carrierList = res.data.map(item=>{
                return {
                    value:item.carrierCode,
                    label:item.carrierCode+' ('+item.carrierName+')',
                }
            })
        })
    },
    methods: {
        ajaxRequest: HttpLabelDifferenceList,
        interceptRequest(params){
            if(params.search.EQ_orgId){
                params.orgId = params.search.EQ_orgId
            }
            if(params.search.EQ_consumeType){
                params.consumeType = params.search.EQ_consumeType
            }
            if(params.search.EQ_billType){
                params.billType = params.search.EQ_billType
            }
            delete params.search.EQ_orgId;
            delete params.search.EQ_consumeType;
            delete params.search.EQ_billType;

            return params
        },
        handleOperates(params="", type,batch) {
            if(batch===true){
                params=(params||this.checkedData.join(','))+'';
                if(!params.length) return this.$Message.warning('请选择至少一条数据');
            }
            switch (type) {
                case 'query':
                    this.operate = {
                        title: '查看',
                        show: true,
                        width: 1200,
                        component: "compUpdate",
                        activeid: params,
                        querytype: 'query',
                        showFooter: false,
                    }
                    break;
                case 'edit':
                    const url1 = this.$router.resolve({ name: 'labelDifferenceDetail', params: { id: params.id}, query: { type, trackingNo: params.trackingNo } });
                    window.open(url1.href, '_blank');
                    break;
                case 'exportQuery':
                    this.handleWebfs(process.env.VUE_APP_APIURL_FBB + "/api/v2/freightSettlementDiff/export", 'download')
                break
                case 'upload':
                    this.operate = {
                        show: true,
                        title: '导入数据',
                        actionurl: process.env.VUE_APP_APIURL_FBB+"/api/v2/freightSettlementDiff/batchImport",
                        name: "multipartFile",
                        component: "compsoUpload",
                        downrul: process.env.VUE_APP_APIURL_FBB+'/api/v2/freightSettlementDiff/diffCostImportTemplate',
                        showFooter:false,
                        width:500,
                    }
                break;
            }
        },
    },
    computed: {
        ...mapGetters('dictionary',['']),
        // 搜索下拉框展示内容
        SearchsData() {
            return  [
                {
                    label: 'Tracking No',
                    tag: 'Input',
                    key: 'EQ_trackingNo',
                    show:true,
                },
                {
                    label: '承运商',
                    tag: 'Select',
                    key: 'EQ_carrierCode',
                    options: this.carrierList,
                    show:true,
                    props:{
                        filterable:true
                    }
                },
                {
                    label: '异常状态',
                    tag: 'Select',
                    key: 'EQ_status',
                    options: this.errStatus,
                    show:true,
                },
            ]
        },
        ToolsData () {
            return [
                {
                    name: "导出",
                    operate: 'exportQuery',
                },
                {
                    name: "导入",
                    theme: 'info',
                    operate: 'upload',
                },
            ]
        },
        // table的展示数据
        columns() {
            return [
                {
                    title: "Tracking No",
                    key: "trackingNo",
                    render:(h,{row})=> {
                        return <div>
                            <a onClick={this.handleOperates.bind(this, {id: row.id, trackingNo: row.trackingNo}, 'edit')}>{row.trackingNo}</a>
                        </div>
                    },
                },
                {
                    title: "承运商",
                    key: "carrierCode",
                },
                {
                    title: "预估金额",
                    key: "estimatedCost",
                    render: (h, { row })=> {
                        return <div>
                            {row.estimatedTotalCost || 0}
                        </div>
                    },
                },
                {
                    title: "实际金额",
                    key: "cost",
                    render: (h, { row })=> {
                        return <div>
                            {row.actualTotalCost || 0}
                        </div>
                    },
                },
                {
                    title: "异常状态",
                    key: "status",
                    render:(h,{row})=> {
                        const status = this.errStatus.filter(item=>item.value == row.status)[0] || [];
                        const color = status.color;
                        return <div style={"color:"+color}>{status.label}</div>
                    },
                },
                {
                    title: "发票号",
                    key: "invoiceNo",
                    render: (h, { row })=> {
                        return <div>
                            {row.invoiceNo || '--'}
                        </div>
                    },
                },
                {
                    title: "发票日期",
                    key: "invoiceDate",
                    render: (h, { row })=> {
                        return <div>
                            {row.invoiceDate || '--'}
                        </div>
                    },
                },
                {
                    title: "结算日期",
                    key: "settlementAt",
                    render: (h, { row })=> {
                        return <div>
                            {row.settlementAt || '--'}
                        </div>
                    },
                }
        ];
        },

    },

};
